<template>
	<view class="advertisement">
		<view class="banner">
			<image :src="img" mode="aspectFill"></image>
		</view>
		<view class="content">
			<view class="g-time">
			{{count}}秒关闭广告<text @click="btnClose">跳过</text>
		</view>
		</view>
	</view>
</template>

<script>
	export default{
		data(){
			return{
				isShow:true,
				count:4,
				img:'',
			}
		},
		async onLoad() {
			let res= await this.$api.post('/banner/getbanner',{PageKey:'开屏广告'})
			this.img=res.data[0].Banner
			if(res.data.length>0){
				this.getclose()
			}else{
				this.count=0
				uni.navigateBack()
			}
			
		  },
		methods:{
			getclose(){
				  let timer = setInterval(() => {
				        if (this.count > 0) {
				            this.count--;
				        } else {
				        clearInterval(timer);
				        uni.switchTab({
				            url:'/pages/tab/assistant'
				         })
				        }
				    }, 1000); // 每隔1秒执行一次倒计时
				},
			btnClose(){
				this.count=0;
				uni.switchTab({
				    url:'/pages/tab/assistant'
				 });
			}	
		}
	}
</script>

<style lang="scss">
	body,html{
		width: 100%;
		height: 100%;
	}
	.advertisement{
		width: 100%;
		height: 100%;
		.banner{
			width: 100%;
			height: 100%;
			image{
				width: 100%;
				height: 100%;
			}
		}
		.content{
			.g-time{
				position: absolute;
				bottom: 90rpx;
				right: 60rpx;
				width: 300rpx;
				height: 70rpx;
				background-color: rgba(0, 0, 0, .3);
				z-index: 99;
				color: #fff;
				text-align: center;
				line-height: 70rpx;
				border-radius: 20rpx;
				text{
					display: inline-block;
					padding-left: 20rpx;
					height: 70rpx;
					color: #fff;
				}
			}
		}
		
	}
</style>